﻿
using System.Xml;

namespace com.uplus.common
{
    /// <summary>
    /// Xml文档管理类
    /// @赵晨亮, 2009-07-09
    /// </summary>
    public class XmlMgr
    {
        #region 节点操作
        /// <summary>
        /// 在指定节点下添加属性
        /// </summary>
        /// <param name="node">要添加属性的节点</param>
        /// <param name="nameValues">名称|值</param>
        public static void AddAttributes(XmlNode node, params string[] nameValues)
        {
            if (node == null) return;
            foreach (string item in nameValues)
            {
                int i = item.IndexOf('|');
                if (i > -1)
                {
                    string name = item.Substring(0, i);
                    string value = item.Substring(i + 1);
                    XmlAttribute xa = node.OwnerDocument.CreateAttribute(name);
                    xa.Value = value;
                    node.Attributes.Append(xa);
                }
            }
        }

        /// <summary>
        /// 获取节点下的属性值
        /// </summary>
        /// <param name="node"></param>
        /// <param name="name"></param>
        /// <returns>value|null</returns>
        public static string GetAttributeValue(XmlNode node, string name)
        {
            string re = null;
            if (node.Attributes[name] != null) re = node.Attributes[name].Value;
            return re;
        }
        #endregion
    }
}
